﻿using System;
using System.Collections.Generic;

namespace Sessionizer.Core.Unity
{
    public sealed class SessionConfiguration : ISessionConfiguration
    {
        public static readonly SessionConfiguration Empty = new SessionConfiguration(new Dictionary<Type, Type>());
       
        private readonly Dictionary<Type, Type> _declarations;

        internal SessionConfiguration(Dictionary<Type, Type> declarations)
        {
            _declarations = declarations;
        }

        public bool IsDeclared(Type type)
        {
            return _declarations.ContainsKey(type);
        }

        public Type Declared(Type type)
        {
            Type factory;
            if (_declarations.TryGetValue(type, out factory))
            {
                return factory;
            }
            throw new ArgumentOutOfRangeException("type", "Type is not registred");
        }
    }
}